/*
This file is part of Cafca.

Cafca is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Cafca is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Cafca.  If not, see <http://www.gnu.org/licenses/>.

If you have any comment, suggestion or idea, do not hesitate to contact me at shenrotin@gmail.com
*/

package org.crag.cafca.util;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Collection;
import java.util.Locale;

import org.crag.cafca.db.SqlConnector;
import org.joda.time.DateTime;
import org.joda.time.TimeOfDay;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class Utilities 
{
	private static DecimalFormatSymbols usSymbols=new DecimalFormatSymbols(Locale.US);
	public static DecimalFormat scientificFormatter= new DecimalFormat("0.####E0",usSymbols);
	public static DecimalFormat standardFormatter= new DecimalFormat("#0.00000",usSymbols);
	public static DecimalFormat percentageFormatter = new DecimalFormat("#0.00000%",usSymbols);
	public static DecimalFormat oneDecimalFormatter = new DecimalFormat("#0.0",usSymbols);
	private static DateTimeFormatter jsonDateTimeFormatter=DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); 
    private static DateTimeFormatter sqlDateTimeFormatter=DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
    private static DateTimeFormatter httpDateTimeFormatter=DateTimeFormat.forPattern("dd/MM/yyyy HH:mm");

    public static DateTime parseJSONDateTime(String dateString,String timeString) 
    {
    	return httpDateTimeFormatter.parseDateTime(dateString+" "+timeString);
    }
    
    public static String dateTimeToSQL(DateTime dateTime) 
    {
    	if (dateTime==null)
    		return null;
    	else
    		return sqlDateTimeFormatter.print(dateTime);
    }

	public static String toJSONDateTime(DateTime dateTime) 
	{
		return jsonDateTimeFormatter.print(dateTime);
	}
}

